package com.kingeid.test;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

/**
 * 测试赣服通扫码页面
 */
public class ScanActivity extends AppCompatActivity {
    private ScanGunKeyEventUtil scanGunKeyEventUtil;

    public static void start(Context context) {
        Intent starter = new Intent(context, ScanActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan);
        scanGunKeyEventUtil = new ScanGunKeyEventUtil();
        scanGunKeyEventUtil.setOnBarCodeCatchListener(new ScanGunKeyEventUtil.OnScanSuccessListener() {
            @Override
            public void onScanSuccess(String barcode) {
                //二维码扫码结果
                Toast.makeText(ScanActivity.this, barcode, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_UP:
                return super.dispatchKeyEvent(event);
        }
        if (scanGunKeyEventUtil != null) {
            scanGunKeyEventUtil.analysisKeyEvent(event);
            return true;
        }
        return super.dispatchKeyEvent(event);
    }

}
